/**
 * 设定管理API服务
 */
import { BaseService, type PageResult } from '../../shared/services/base-service'
import type { ApiResponse } from '../../../types/api'

// 设定实体类型
export interface BookSetting {
  id?: number
  title: string
  content: string
  description?: string
  tags?: string
  importance?: number
  type?: string
  bookId: number
  createTime?: string
  updateTime?: string
}

// 分页查询参数
export interface BookSettingQueryParams {
  page: number
  size: number
  title?: string
  bookId?: number
}

// 设定管理API服务
class BookSettingService extends BaseService {
  // 获取设定列表（分页）
  async getSettings(params: BookSettingQueryParams): Promise<ApiResponse<PageResult<BookSetting>>> {
    return this.get('/novel/setting/list', params)
  }

  // 获取设定详情
  async getSettingById(id: number): Promise<ApiResponse<BookSetting>> {
    return this.get(`/novel/setting/${id}`)
  }

  // 创建设定
  async createSetting(setting: BookSetting): Promise<ApiResponse<BookSetting>> {
    return this.post(`/novel/setting/book/${setting.bookId}`, setting)
  }

  // 更新设定
  async updateSetting(setting: BookSetting): Promise<ApiResponse<BookSetting>> {
    return this.put(`/novel/setting/${setting.id}`, setting)
  }

  // 删除设定
  async deleteSetting(id: number): Promise<ApiResponse<string>> {
    return this.delete(`/novel/setting/${id}`)
  }

  // 获取书籍设定列表
  async getSettingsByBookId(bookId: number): Promise<ApiResponse<BookSetting[]>> {
    return this.get(`/novel/setting/book/${bookId}`)
  }
}

export const bookSettingService = new BookSettingService()